<?php
	Util::registerScriptFile(Util::themeUrl().'/js/custome.datepicker.js');
	Util::registerScriptFile(Util::themeUrl().'/js/jquery.js');
	Util::registerScriptFile(Util::themeUrl().'/css/jquery-ui.css');
	Util::registerScriptFile(Util::themeUrl().'/js/jquery-ui.min.js');
?>
<input type="hidden" value="<?php echo $visit_delete;?>" id="visit_id_delete" name="visit_id_delete" />
<table class="education-form" id="legend-box-5">
	<tr valign="top">
		<td>
			<div class="legendColorBox">
				<div style="background: #8ec657" id="visit-add" class="legendColor add-semester">Thêm</div>
				<input type='hidden' id="tr-index" value=<?php echo $count_visit;?>>
			</div>
		</td>
	</tr>
	<tr id="education-detail" valign="top" <?php echo ((empty($donorvisit)) ? 'style="display: none"' : null);?>">
		<td>&nbsp;</td>
		<td class="border-bottom border-right border-left border-top">
			<table id="visit-table">
			<?php if (!empty($donorvisit)) :?>
				<?php foreach ($donorvisit as $visit => $eachVisit): ?>
					<tr id="visit-tr-<?php echo $visit;?>" class="semester border-bottom" valign="top">
						<td class="visit-date">
							<?php if (isset($eachVisit['visit_id'])):?>
							<input type="hidden" name="DonorVisit[<?php echo $visit;?>][visit_id]" value="<?php echo $eachVisit['visit_id']?>">
							<?php endif;?>
							<input type="text" class="picker-date" value="<?php echo $eachVisit['visit_date'];?>" name="DonorVisit[<?php echo $visit;?>][visit_date]" id="visit_date-<?php echo $visit;?>">
						</td>
						<td class="visit-comment">
							<input type="text" value="<?php echo $eachVisit['visit_comment'];?>" name="DonorVisit[<?php echo $visit;?>][visit_comment]" id="visit_comment-<?php echo $visit;?>">
							<span <?php echo (isset($eachVisit['visit_id'])) ? 'id = "' . $eachVisit['visit_id'] . '"' : '';?> class="delete-visit collapse-toggle-delete">&nbsp;&nbsp;</span>
						</td>

					</tr>
				<?php endforeach;?>
			<?php endif?>
			<?php for ($visit = $count_visit; $visit < $count_visit + 50; $visit++) : ?>
				<tr id="visit-tr-<?php echo $visit;?>" class="semester border-bottom" valign="top" style="display:none;">
					<td class="visit-date">
						<input type="text" class="picker-date" value="" name="DonorVisit[<?php echo $visit;?>][visit_date]" id="visit_date-<?php echo $visit;?>">
					</td>
					<td class="visit-comment">
						<input type="text" value="" name="DonorVisit[<?php echo $visit;?>][visit_comment]" id="visit_comment-<?php echo $visit;?>">
						<span class="delete-visit collapse-toggle-delete">&nbsp;&nbsp;</span>
					</td>
				</tr>
			<?php endfor;?>
			</table>
		</td>
	</tr>
</table>
<script type="text/javascript">
	$(".delete-visit").live("click", function(event){
		var answer = confirm("Bạn muốn xóa dữ liệu này ?");
	    if (answer){
	    	if (this.id != '') {
				var id_delete 	= $("#visit_id_delete").val();
				id_delele		= id_delete + ((id_delete != '') ? ',' : '') + this.id;
				$("#visit_id_delete").val(id_delele);
			}

	    	$(this).closest("tr").remove();
	    }
	    return false;
	});
	$("#visit-add").click(function(){
		$("#education-detail").css('display','');
		index_semester = $("#tr-index").val();
		addVisit(index_semester);
	});
	function addVisit(index) {
		$("#visit-tr-" + index).css('display','');
		var cur_index = parseInt($("#tr-index").val());
		$("#tr-index").val(cur_index + 1);
	}
	$("#updateVisit").live("click", function(event){
		for (i = <?php echo $count_visit;?>; i < <?php echo $count_visit + 50; ?>; i++) {
			var visit_date = $("#visit_date-" + i).val();
			if (visit_date == '') {
				$("#visit-tr-" + i).remove();
			}
		}
	});
</script>
